package com.lyfx.ly.controller;

import java.util.Arrays;
import java.util.Map;

import com.lyfx.ly.vo.RouteRespAllVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lyfx.ly.entity.StudyRouteEntity;
import com.lyfx.ly.service.StudyRouteService;
import com.lyfx.common.utils.PageUtils;
import com.lyfx.common.utils.R;



/**
 * **课程学习路线表**
 *
 * @author lsy
 * @email lsy@gmail.com
 * @date 2020-07-05 18:03:59
 */
@RestController
@RequestMapping("ly/studyroute")
public class StudyRouteController {
    @Autowired
    private StudyRouteService studyRouteService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("ly:studyroute:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = studyRouteService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{routeId}")
    @RequiresPermissions("ly:studyroute:info")
    public R info(@PathVariable("routeId") Long routeId){
        StudyRouteEntity studyRoute = studyRouteService.getById(routeId);

        return R.ok().put("studyRoute", studyRoute);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("ly:studyroute:save")
    public R save(@RequestBody StudyRouteEntity studyRoute){
        studyRouteService.save(studyRoute);

        return R.ok();
    }


    /**
     * 保存
     */
    @RequestMapping("/save/baseValuse")
    @RequiresPermissions("ly:studyroute:save")
    public R saveBaseValuse(@RequestBody RouteRespAllVo studyRoute){
        studyRouteService.saveBaseValuse(studyRoute);
        return R.ok();
    }
    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("ly:studyroute:update")
    public R update(@RequestBody StudyRouteEntity studyRoute){
        studyRouteService.updateById(studyRoute);

        return R.ok();
    }


    @RequestMapping("/update/status")
    @RequiresPermissions("ly:studyroute:update")
    public R updateStatus(@RequestBody StudyRouteEntity studyRoute){
        studyRouteService.updateStatus(studyRoute);
        return R.ok();
    }
    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("ly:studyroute:delete")
    public R delete(@RequestBody Long[] routeIds){
        //删除此表和关联表里的信息
        studyRouteService.removeToall(Arrays.asList(routeIds));

        return R.ok();
    }

}